from model.Ship_class import *
import xlrd

shiplist = []
det_sum = 0
def ship_init():
    finish_task = []
    # with open('thread-1.txt', 'r') as f:
    #     t1 = f.readlines()
    #     for i in t1:
    #         ind = i.split(' ')[1].split('\n')[0]
    #         finish_task.append(int(ind))
    # print(finish_task)
    # with open('thread-2.txt', 'r') as f:
    #     t1 = f.readlines()
    #     for i in t1:
    #         ind = i.split(' ')[1].split('\n')[0]
    #         finish_task.append(int(ind))
    # with open('thread-3.txt', 'r') as f:
    #     t1 = f.readlines()
    #     for i in t1:
    #         ind = i.split(' ')[1].split('\n')[0]
    #         finish_task.append(int(ind))

    # 读取船只信息
    filename = '附件2.xls'
    rdexcel = xlrd.open_workbook(filename)
    this_sheet_name = rdexcel.sheet_names()    # 读取页名
    my_sheet = rdexcel.sheet_by_name(this_sheet_name[0])
    rows = my_sheet.nrows   # 总行数


    # 根据excel表中数据实例化对象
    for i in range(1, rows):
        this_index = int(my_sheet.cell(i, 0).value)   # 船序号
        this_x = float(my_sheet.cell(i, 1).value)       # x坐标
        this_y = float(my_sheet.cell(i, 2).value)       # y坐标
        this_speed = float(my_sheet.cell(i, 3).value)   # 航速
        this_cls = my_sheet.cell(i, 4).value     # 类别
        if this_cls == 'Ⅱ类':
            shiplist.append(ship(this_index, this_x, this_y, this_speed, this_cls))


    # 根据到达cd线的时间进行升序排列
    for each_ship in shiplist:
        each_ship.rest_time()
    shiplist.sort(key=lambda ship: ship.res)
    shiplist_copy = []
    for each_ship in shiplist:
        shiplist_copy.append(each_ship)
        # print(each_ship.index)



    # print('2222222222')
    # for each_task in finish_task:
    #     for i in shiplist:
    #         if i.index == each_task:
    #             shiplist.remove(i)

    # for each_ship in shiplist:
    #     print(each_ship.index)